<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>社保稽查 登陆</title>
    <c:set var="path" value="${pageContext.request.contextPath}"/>
    <link rel="stylesheet" href="${path}/plugins/assets/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="${path}/plugins/assets/css/style.css">
    <link rel="stylesheet" href="${path}/plugins/assets/font-awesome/css/font-awesome.min.css">
    <script src="${path}/plugins/bootstrap/js/jquery.min.js"></script>
    <script src="${path}/plugins/assets/bootstrap/js/bootstrap.min.js"></script>
    <script src="${path}/plugins/assets/js/jquery.backstretch.min.js"></script>
    <script src="${path}/plugins/assets/js/jquery.validate.min.js"></script>
    <script type="text/javascript">
        function changeImage() {
            $("#captchaImage").prop("src", "${path}/User/imgCode?time=" + new Date().getTime());
        }

        function subs() {
            let username = $("#form-username").val();
            let password = $("#form-password").val();
            let imgCode = $("#ImgCode").val();

            if (username == "" || username == null) {
                alert("请输入用户名");
                return;
            }
            if (!(/^[a-zA-Z]\w{3,15}$/.test(username))) {
                alert("请输入4到16位(字母,数字,下划线,减号)用户名");
                return;
            }

            if (password == "" || password == null) {
                alert("请输入密码");
                return;
            }
            if (!(/^\w{5,17}$/.test(password))) {
                alert("密码至少6位");
                return;
            }
            if (imgCode == "" || imgCode == null) {
                alert("请输入验证码");
                return;
            }
            $.ajax({
                url: "${path}/User/login",
                type: "post",
                data: "username=" + username + "&password=" + password + "&ImgCode=" + imgCode,
                dataType: "json",
                success: function (status) {
                    var text = $("#text").val();
                    var texts = $("#texts").val();
                    if (status == "true") {
                        if (text != null) {
                            $("#text").html("");
                        }
                        $("#texts").html("登录成功");
                        location.href = "${path}/index.jsp";
                    } else {
                        if (texts != null) {
                            $("#texts").html("");
                        }
                        $("#text").html(status);
                        if (status == "账户不存在...") {
                            $("#form-username").val('');
                        } else if (status == "密码错误...") {
                            $("#form-password").val('');
                        } else if (status == "验证码错误...") {
                            $("#ImgCode").val('');
                            changeImage();
                        }
                    }
                }
            })
        }
    </script>
</head>
<body style="background: url(${path}/plugins/assets/img/backgrounds/235.jpg)">
<div class="top-content">
    <div class="inner-bg">
        <div class="container">
            <div class="row">
                <div class="text text-center">
                    <h1><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;稽查平台</strong></h1>
                    <br/><br/>
                </div>
                <div class="form-top col-lg-offset-4" style="width: 450px">
                    <div class="form-top-left">
                        <h3>后台管理登陆</h3>
                        <p>请输入账户,密码然后摁下登录键</p>
                    </div>
                    <div class="form-top-right">
                        <i class="fa fa-key"></i>
                    </div>
                </div>

                <div class="form-bottom col-lg-offset-4" style="width: 450px">
                    <span class="text" id="text" style="color: red"></span>
                    <span class="texts" id="texts" style="color: #00ca6d"></span>
                    <div class="pull-right">
                        <a class="btn-xs btn-link" href="${path}/insert.jsp">还没账户? 去注册</a>
                    </div>
                    <br/>
                    <%--<c:if test="${Error!=null}">${Error}</c:if>--%>
                    <form role="form" action="" method="post" class="login-form" id="loginForm">
                        <span id="msgDiv"></span>
                        <div class="form-group">
                            <label class="sr-only" for="form-username">Username</label>
                            <input type="text" name="username" placeholder="请输入用户名..."
                                   class="form-username form-control" required id="form-username">
                        </div>
                        <div class="form-group">
                            <label class="sr-only" for="form-password">Password</label>
                            <input type="password" name="password" placeholder="请输入密码..."
                                   class="form-password form-control" required id="form-password">
                        </div>
                        <div class="form-group">
                            <div class="form-group">
                                <img id="captchaImage" style="height: 32px;float: left" onclick="changeImage()"
                                     class="captchaImage" src="${path}/User/imgCode" width="80px" height="18px"/>
                                <label class="sr-only" for="form-password">ImgCode</label>
                                <input style="width: 300px;float: left;margin-left: 20px" type="text" name="ImgCode"
                                       id="ImgCode"
                                       placeholder="请输入验证码..."
                                       class="form-password form-control" required id="form-ImgCode">
                            </div>
                            <br/>
                        </div>
                        <button type="button" onclick="subs()"
                                style="width: 400px;border:1px solid #90919d;border-radius: 4px; color: #010101"
                                value="登录">登录
                        </button>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
</body>